package com.umeng.analytics.pro;

import android.content.Context;
import android.text.TextUtils;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class bf {
    private final Map a = new HashMap();
    private static JSONObject b = new JSONObject();

    public bf() {
    }

    public static void a(Context arg5) {
        JSONObject v1;
        if (arg5 == null) {
            return;
        }

        try {
            v1 = bf.b;
            synchronized (v1) {
                if (bf.b.length() > 0) {
                    w.a(arg5).a(bd.a(), bf.b, w.w$a.PAGE);
                    bf.b = new JSONObject();
                }

            }
            return;

        } catch (Exception v0) {
            v0.printStackTrace();
        }
    }

    public void a(String arg5) {
        if (!TextUtils.isEmpty(((CharSequence) arg5))) {
            Map v1 = this.a;
            synchronized (v1) {
                this.a.put(arg5, Long.valueOf(System.currentTimeMillis()));
            }
        }
    }

    public void a() {
        long v0_2;
        Object v2_1;
        Object v4 = null;
        long v2 = 0;
        Map v5 = this.a;
        synchronized (v5) {
            try {
                Iterator v6 = this.a.entrySet().iterator();
                while (true) {
                    if (!v6.hasNext()) {
                        break;
                    }
                    Object v0_1 = v6.next();
                    if (((Long) ((Map.Entry) v0_1).getValue()).longValue() > v2) {
                        long v10 = ((Long) ((Map.Entry) v0_1).getValue()).longValue();
                        v2_1 = ((Map.Entry) v0_1).getKey();
                        v0_2 = v10;
                    } else {
                        v0_2 = v2;
                        v2_1 = v4;
                    }
                    v4 = v2_1;
                    v2 = v0_2;
                    continue;
                }
            } catch (Throwable v0) {

            } finally {
                if (v4 != null) {
                    this.b(((String) v4));
                }
            }
        }
    }

    public void b(String arg6) {
        Object v0_1;
        Map v1;
        if (!TextUtils.isEmpty(((CharSequence) arg6))) {
            v1 = this.a;
            synchronized (v1) {
                v0_1 = this.a.remove(arg6);
            }
            if (v0_1 != null) {
                long v0_2 = System.currentTimeMillis() - ((Long) v0_1).longValue();
                JSONObject v2 = bf.b;
                synchronized (v2) {
                    try {
                        JSONObject v3 = new JSONObject();
                        bf.b = v3;
                        v3.put("page_name", arg6);
                        bf.b.put("duration", v0_2);
                    } catch (Throwable v0) {
                    }
                }
            }
        }
    }
}

